<html>
    <head>
        <title><?php echo $store_name;?></title>
        <meta charset="UTF-8">
        <meta name="description" content="<?php echo $action['action_name'];?>">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-1.11.2.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_?>';
        </script>
    </head>
    <body>
<div class="container">
    <div class='_main_'>
<link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-1.11.2.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
<div style='height:1.5rem'></div>
<span ><input id='checkAll' name="checkAll" type="checkbox" value="" onclick='checkAll(1)' /><?php echo $store_name;?></span>
<br>
<div><hr></div>
<form id='form' >
    <?php $i =0; foreach($carts as $k=>$v){ if($v['id']==''){ continue; }  ?>
    <div class='row'>
        <?php if($v['status']!=0){ ?>
        <span style='float:left;padding:1rem;'><input id='check<?php echo $i;?>' name="check" onclick='checka(<?php echo $i;?>)' type="checkbox" value="" /></span>
        <?php }else{ ?>
        <span style='float:left;padding:2rem;'></span>
        <?php } ?>
        <div class='thumbnail' style="float:left;">
            <div style="height:15rem;width:15rem;overflow: hidden;">
                <img class='_img' src="<?php echo 'http://'.IMAGE_DOMAIN_.$v['images'][0]['image'];?>" style='width:100%;height:100%'/>
            </div>
        </div>
        <div>
            <div ><?php echo $v['name'];?></div>
            <div ><?php echo $v['title'];?></div>
            <div class='_line'></div>
            <input type='hidden' name='item_id' value='<?php echo $v['id']; ?>' >
            <input type='hidden' id='price-<?php echo $i ?>' value='<?php echo $v['price'];?>'>
            <div ><i><font style='color:red;font-size:1.7rem'>￥<?php echo $v['price']/100;?></font></i></div> 
            <?php if($v['status']==0){ ?>
              <div ><i><font style='color:red;font-size:1.7rem'>该商品已更新</font></i></div>  
            <?php } ?>
            <div style='float:right;margin-top:7rem' >

                <input type='hidden' name='' value='<?php echo $v['item_number']; ?>' >
                <input class="min" name="" type="button" value="-"  />
                <input class="text_box" name="goodsnum" id='goodsnum-<?php echo $i;?>' type="text" oninput='number(<?php echo $i;?>)'  value="1" style="width:35px;" />
                <input class="add" name="" type="button" value="+"  /> 
            </div>
        </div>
    </div>
    <?php $i++; }?>
</form>
<div  style='float:left;width:37%;' ><hr></div>
<span style='font-size:1.5rem'> 为 你 推 荐 </span>
<div  style='float:right;width:37%;' ><hr></div>
<?php foreach($items as $k=>$v){?>
<?php if($k%2==0){ ?>
    <div class='row'>
        <?php   }?>
    
        <div class='thumbnail' style="float:left;width:50%">
            <div style="overflow: hidden;">
                <a target="_blank" href="<?php echo shop_buildUrl('/user/shop/info?item_id='.$v['id']);?>"><img class='_img' src="<?php echo 'http://'.IMAGE_DOMAIN_.$v['images'][0]['image'];?>" style='height:160px;'/></a>
            </div>
            <div>
                <div ><?php echo $v['name'];?></div>    
                <div ><i>价格：<font style='color:red;font-size:1.7rem'>￥<?php echo $v['price']/100;?></font></i></div>
            </div>
        </div>
    
<?php if(($k+1)%2==0 || $items[$k+1]['id']<1){   ?>
    </div>
<?php } ?>
<?php } ?>
</div>
<div class='box navbar-fixed-bottom' style="margin-bottom:60px;background-color:#EEEEEE;">
    <span style='float:left;padding:1rem;'><input id='checkAlla' name="checkAlla" type="checkbox" value="" onclick='checkAll(2)' />全选</span>
    <button class="btn btn-primary btn-lg"  type="button" id='settle' style="width:30%;background-color:#FF79BC;border-color:white;float:right;">去结算(<span id='num' >0</span>)</button>
    <span style='padding:1rem;float:right;'>共计：<span style='text-align:right'>￥<span id='money' style='color:red;font-size:1.7rem;'>0</span><br> (不含优惠劵)</span></span>&nbsp;&nbsp;&nbsp;
</div>


<div class='_line'></div>
<div class='_line'></div>
<div id='showCodes' style="text-align:center;width:100%;height:100%;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
    background-color:rgba(0, 0,0, 0.5);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none "> 
    <div class="settle_div" >
        <img width='25px'; id='down' style='float:right;margin-top:-1rem;margin-right:-1rem' src='/public/images/error1.png' >
        <div style='padding:4rem;'>
    <form action='/user/shop/mobile?store_id=<?php echo $v['store_id'];?>' method="get" id='login_form'>
        <?php if($_GET["msg"]==1){?>
        <div><font style="color:red">账号或验证码错误</font></div>
        <?php }?>

        <div class='form-group' id='appends'>
            <input type='hidden' name='store_id' value='<?php echo $v['store_id']; ?>' >
            <input type='hidden' name='rmb' id='rmb' value='0' > 
            <input type="text" class="form-control" id='mobile' name='mobile' placeholder="请输入手机号" value=""/>
        </div>
        <div class='form-group' style="text-align: right">
            <input type="text" class="form-control" name="code" placeholder="验证码" value=""/><br/>
            <button type="button" id='subcode' onclick="_code();" style='width:10rem'>获取验证码</button>
        </div>
        <div class="form-group login_sub">
            <input type="submit" class="btn btn-info" name="submit"   value="提交">
        </div>
    </form>
    </div>
</div>

</div>

</body></html>

<script type="text/javascript">
    $(document).ready(function(){
        if("<?php echo $_GET['msg'] ?>" ==1){
            alert('验证码错误！');
        }
        $(".add").click(function() {
            $(this).prev().val(parseInt($(this).prev().val()) + 1);
            name = $(this).prev().prop("id");
            k = name.replace(/[^0-9]/ig,"");
            if($('#check'+k).is(':checked')){
                ch(k);
            }  
        });
        $(".min").click(function() {
            $(this).next().val(parseInt($(this).next().val()) - 1);
            if(parseInt($(this).next().val())<=0){
                if(confirm("确将该商品移出购物车?")){
                    item_number = $(this).prev().val();
                    $.ajax({
                        url:"<?php echo shop_buildUrl('/user/shop/delfrom?item_number="+item_number+"');?>",async:true, 
                        success: function(msg){
                            if(msg == 'false'){
                                return;
                            }
                            if(msg == 1){
                                alert('成功移除！');
                                window.location.reload(); 
                            }
                        }
                    });
                        
                    
                }else{
                    $(this).next().val(parseInt($(this).next().val()) + 1);
                    return;
                }
            }
            name = $(this).next().prop("id");
            k = name.replace(/[^0-9]/ig,"");
            if($('#check'+k).is(':checked')){
                ch(k);
            } 

        });
        $('#settle').click(function(){
            if(! $(":checkbox[name='check']").is(':checked')) {
                alert('请先选择商品！');
                return;
            }
            if($(":checkbox[name='check']").is(':checked')){
                var m = $(":checkbox[name='check']").length;
                var rmb =0;
                for(i=0;i<m;i++){
                    if($('#check'+i).is(':checked')){
                        item_id = Number($('#price-'+i).prev().val());
                        price = Number($('#price-'+i).val());
                        num = Number($('#goodsnum-'+i).val());
                        rmb += Number(price*num);
                        var html = '';
                        html += "<input type='hidden' name='item_id[";
                        html += i;
                        html += "]' value=";
                        html += item_id; 
                        html += " >";
                        html += "<input type='hidden' name='price[";
                        html += i;
                        html += "]' value=";
                        html += price; 
                        html += " >";
                        html += "<input type='hidden' name='num[";
                        html += i;
                        html += "]' value=";
                        html += num; 
                        html += " >";
                        $('#appends').append(html);
                        html = '';
                        
                    }else{
                        continue;
                    }
                }         
            }
            $('#rmb').val(rmb);
            session = "<?php  echo $_SESSION['client_id'];?>";
            store_id = "<?php  echo (int)$_GET['store_id']; ?>";
            if(session>1){
                if(confirm('我们将发送验证码到你的手机，请注意查收！')){
                    var sj = "<?php echo $_SESSION['msg_mobile']; ?>";
                    $('#mobile').val(sj);
                    $('#showCodes').show();
                    _code();
                }else{
                    return;
                }
            }else{
                $('#showCodes').show();
            }
            
            
        });

        $('#down').click(function(){
            $('#showCodes').hide();
        });
        
    })
function ch(k){
        money =0;
        nums = 0;
        var n = $(":checkbox[name='check']").length;
        for(i=0;i<n;i++){
            if($('#check'+i).is(':checked')){
                price = Number($('#price-'+i).val());
                num = Number($('#goodsnum-'+i).val());
                if(num<1){
                    alert('商品数量不能小于1');
                    return;
                }
                nums= Number(nums+1);
                mon= Number(price*num);
                money = Number(money+mon);
            }else{
                continue;
            }
        }
        $('#money').html(money/100);
        $('#num').html(nums);
}
function checkAll(t){
    if(t==1){
        if($('#checkAll').is(':checked')){
            $('#checkAlla').prop('checked',true);
        }else{
           $('#checkAlla').prop('checked',false);
        }
    }
    if(t==2){
        if($('#checkAlla').is(':checked')){
            $('#checkAll').prop('checked',true);
        }else{
            $('#checkAll').prop('checked',false);
        }
    }
    if($('#checkAlla').is(':checked')){   
        $(":checkbox[name='check']").prop("checked", true);
        ch(0);
    }else{
        $(":checkbox[name='check']").prop('checked',false);
        $('#money').html(0);
        $('#num').html(0); 
    }
}
function checka(k){
    $('#checkAll').prop('checked',false);
    $('#checkAlla').prop('checked',false);
    ch(k);
   
}

function number(k){
    if($('#check'+k).is(':checked')){
        ch(k);
    }

}



$("#login_form").validate({
        rules: {
            mobile: {
                required: true,
                number: true,
                mobile: true

            },
            code: {
                required: true,
                rangelength: [6, 6]
            }
        },
        messages: {
            mobile: {
                required: '请输入手机号',
                number: '请输入手机号',
                mobile: '请输入手机号'
            },
            code: {
                required: '请输入验证码',
                rangelength: '请输入验证码'
            }
        }
    });
    jQuery.validator.addMethod("mobile", function (value, element) {
        var length = value.length;
        var mobile = /^(((1[1-9]{1}[0-9]{1})|(15[0-9]{1}))+\d{8})$/
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "手机号码格式错误");

    function _code() {
        var mobile = $("#mobile").val();
        $.ajax({url: "/user/barber/code?mobile=" + mobile, async: true, success: function (msg) {
                if (msg != 'true') {
                    alert(msg);
                    return false;
                }
                $("#subcode").text('60');
                $("#subcode").attr('disabled', 'disabled');
                var t = setInterval(function () {
                    var m = $("#subcode").text();
                    var str = parseInt(m) - 1;
                    if (str <= 0) {
                        str = '获取验证码';
                        $("#subcode").removeAttr('disabled');
                        clearInterval(t);
                    }
                    $("#subcode").text(str);
                }, 1000);
            }
        });
    }


</script> 

